import { dialogJs } from "~/composables/common/dialog";
import { userSet } from "~/composables/common/user";
const { diaLogShow } = dialogJs();
const { getToken } = userSet();
import { ref } from "vue";
export const sidebarClick = () => {
  const route = useRoute();
  const isSetting = ref(false);
  const isRouteActive = (path: string) => {
    // 完全匹配
    if (route.path === path) {
      return true;
    }
    // 子路径匹配（例如 /course 匹配 /course/sentence）
    if (path !== "/" && route.path.startsWith(path + "/")) {
      return true;
    }
    return false;
  };
  const goTo = (path: string) => {
    if (path === "/course" || path === "/course/sentence") {
      return navigateTo(path);
    }
    if (!getToken()) {
      diaLogShow({
        title: "提示",
        content: "您还没有登录，是否立即登录？",
        link: "/login",
        confirmText: "立即登录",
      });
      return;
    }
    return navigateTo(path);
  };
  const closeSettingDialog = () => {
    isSetting.value = false;
  };
  return { isRouteActive, goTo, closeSettingDialog, isSetting };
};
